<template>
  <div class="page">
    <div class="weui-cells clist">
      <div class="weui-cell" v-for="(item,index) in resultList" :key="index" @click="goList(item)">
        <a  class="weui-cell__hd">
          <img class="c_pic" :src="item.image" mode="widthFix">
        </a>
        <div class="weui-cell__bd" >
          <a  class="c_name">{{item.username}}</a>
          <div class="weui-flex c_tel">
            <div class="weui-flex__item"><span>电话：</span>{{item.mobileNo}}</div>
            <a @click.stop="callPhone(item.mobileNo)"><img src="../../../static/images/tel.png"></a>
          </div>
          <!-- <div class="c_date"><span>有效期：</span>{{item.createTime}} 至{{item.expriyTime}}</div> -->
        </div>
      </div>
         <div v-if="!resultList.length" class="weui-cell" style="display: flex;justify-content: center;">
          暂无更多数据
          </div>
    </div>
    <div class="footbtn">
      <a href="/pages/addcustomer/main">新增客户</a>
    </div>
  </div>
</template>

<script>
import card from '@/components/card'
 import * as appId from "@/utils/util"
 import {getTIme} from "@/utils/util.js"
export default {
  data () {
    return {
      current: 0,
	  userId:"",
	  phone:"",
	  userId:"",
	  pageNo:1,
	  pageSize:10,
	  resultList:[],
	  result:[]
    }
  },

  components: {
    card
  },
  onPullDownRefresh(){
     console.log('down')
      if(this.result.length){
     this.pageNo++;
    }

     this.getList()

  },
   onShow(){
     wx.setNavigationBarTitle({
       title: "我的顾客"
     })
	 this.userInfo =wx.getStorageSync('userInfo')&&JSON.parse(wx.getStorageSync('userInfo'))
	 if(this.userInfo) {
	   this.phone=this.userInfo.mobileNo;
	   this.userId=this.userInfo.baseUserId;
	   this. getList()



	 }else{
	   wx.showToast({
	     title:'请先登录',
	     icon: 'none',
	     duration: 2000
	   })
	 }
   },
  methods: {
    callPhone(phone){
      wx.makePhoneCall({
        phoneNumber: phone //仅为示例，并非真实的电话号码
      })
    },
    goList(item){
      const url = `/pages/customerorder/main?cardId=${item.cardId}&phone=${item.mobileNo}&img=${item.image}&name=${item.username}`

        mpvue.navigateTo({ url })

    },
    getTIme,
	 getList(){
     let that=this;
		 this.$http.request({
		           method:"post",
		           url:"/v1.0/appletLogin/myCustomersList",
		           body:{
		 					   "appid":appId.appId,
		 					   	"phone":this.phone,
		 					   	"pageNo":this.pageNo,
		 					   	"pageSize":this.pageSize,
		 					   	"userId":this.userId
		 				   }
		 }).then((data)=>{
			 if(data.code==0){
			   that.result=data.result;
			    if (that.pageNo > 1) {
			   that.resultList.push(...data.result)
			     console.log(that.resultList)
			   }else{
			     that.resultList=data.result;
           this.resultList.forEach((a,i)=>{
             a.createTime=this.getTIme(a.createTime)
           })
			   }
			    if(!data.length){
			    wx.stopPullDownRefresh();
			 //    wx.showToast({
			 //   title: '暂无更多数据',
			 //   icon: 'none',
			 //   duration: 2000
			 // })
			 }

			 }else{
			    wx.showToast({
			   title: `${data.message}`,
			   icon: 'none',
			   duration: 2000
			 })
			 }
		 })


	 },
    bindViewTap () {
      const url = '../logs/main'
      if (mpvuePlatform === 'wx') {
        mpvue.switchTab({ url })
      } else {
        mpvue.navigateTo({ url })
      }
    }
  },

  created () {
    // let app = getApp()
  }
}
</script>

<style scoped>
.page{
  padding-bottom: 4em;
}
.c_name{
  display: block;
}
.clist{
  font-size: 0.8em;
}
.c_pic{
  width: 5.4em;
  height: 5.4em;
  border-radius: 50%;
  margin-right: 0.7em;
}
.c_tel{
  font-size: 0.8em;
  padding:0.3em 0 0.4em 0;
}
.clist span{
  color: #999;
}
.c_tel img{
  width: 1.4em;
  height: 1.4em;
}
.c_date{
  font-size: 0.8em;
}
.footbtn{
  position: fixed;
  bottom: 0px;
  left: 0px;
  right: 0px;
  background: #fff;
  border-top: 1px #eee solid;
  padding: 0.6em 2em;
  z-index: 9999;
}
.footbtn a{
  display: block;
  height: 2.4em;
  border-radius: 1.2em;
  background: #FF787E;
  color: #fff;
  line-height: 2.4em;
  text-align: center;
  color: #fff;
  font-size: 1em;
}
</style>
